//
// Created by work on 24-6-6.
//

#include "iot_model_device/CRtModelParameterInfo.h"

namespace iotplat {

    std::map<CRtModelParameterInfo::EModelParameterCol, std::string> CRtModelParameterInfo::rtModelParameterColToStringMap = {
            {CRtModelParameterInfo::EPtype, "ptype"},
            {CRtModelParameterInfo::EEn_write, "en_write"},
            {CRtModelParameterInfo::EEn_read, "en_read"}
    };
    std::map<CRtModelParameterInfo::EModelParameterCol, CValue::EValueType> CRtModelParameterInfo::rtParameterDataTypeByField = {
            {CRtModelParameterInfo::EPtype, CValue::IOT_Int},
            {CRtModelParameterInfo::EEn_write, CValue::IOT_Bool},
            {CRtModelParameterInfo::EEn_read, CValue::IOT_Bool}
    };


    CRtModelParameterInfo::CRtModelParameterInfo(){

    }

    void CRtModelParameterInfo::fromJson(Json::Value json) {
        model_name = json[baseSigFieldName(BASE_SIG_ENUM::EModel_name)].asString();
        user = json[baseSigFieldName(BASE_SIG_ENUM::EUser)].asString();
        name = json[baseSigFieldName(BASE_SIG_ENUM::EName)].asString();
        descr = json[baseSigFieldName(BASE_SIG_ENUM::EDescr)].asString();
        sn = json[baseSigFieldName(BASE_SIG_ENUM::ESn)].asInt();
        grouping = json[baseSigFieldName(BASE_SIG_ENUM::EGrouping)].asString();
        configs = json[baseSigFieldName(BASE_SIG_ENUM::EConfigs)];
        ptype = static_cast<EParameterType>(json[parameterFieldName(PARAMETER_ENUM::EPtype)].asInt());
        en_write = json[parameterFieldName(PARAMETER_ENUM::EEn_write)].asBool();
        en_read = json[parameterFieldName(PARAMETER_ENUM::EEn_read)].asBool();
    }

    Json::Value CRtModelParameterInfo::toJson() {
        Json::Value json;
        json[baseSigFieldName(BASE_SIG_ENUM::EModel_name)] = model_name;
        json[baseSigFieldName(BASE_SIG_ENUM::EUser)] = user;
        json[baseSigFieldName(BASE_SIG_ENUM::EName)] = name;
        json[baseSigFieldName(BASE_SIG_ENUM::EDescr)] = descr;
        json[baseSigFieldName(BASE_SIG_ENUM::ESn)] = sn;
        json[baseSigFieldName(BASE_SIG_ENUM::EGrouping)] = grouping;
        json[baseSigFieldName(BASE_SIG_ENUM::EConfigs)] = configs;
        json[parameterFieldName(PARAMETER_ENUM::EPtype)] = static_cast<int>(ptype);
        json[parameterFieldName(PARAMETER_ENUM::EEn_write)] = en_write;
        json[parameterFieldName(PARAMETER_ENUM::EEn_read)] = en_read;
        return json;
    }
} // iotplat